package sensornetwork.sensor;

import snifc.sensor.CaptorIfc;
import snifc.PacketIfc;
import sensornetwork.Packet;


public class Captor implements CaptorIfc{
	
	private int idSensor;
	private boolean isReady;
	private int compteur;
  private int ttlMax;
	
	public Captor (int idSensor, int ttlMax){
		this.idSensor = idSensor;
    this.ttlMax = ttlMax;
		this.isReady = false;
	}
	
	public void triggerCapture(){
		isReady = true;
	}
	
	public PacketIfc capture() throws Exception {
		if ( isReady == false) {
			 throw new Exception("Paquet non genere sur le sensor : "+idSensor);
    } else {
      isReady = false; 
      int id = Integer.valueOf("" + idSensor + compteur);
      Packet newpacket = new Packet (this.idSensor, id, ttlMax);
      compteur++;
      System.out.println("Packet " + newpacket.getId() + " is Generated on sensor # " + idSensor);
      return (newpacket);
    }
	}
}
